package com.si.sea_island.mapper;

import com.si.sea_island.pojo.game.Shop;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @Description ShopMapper
 * @Author weijunhao
 * @Date 2024-12-17
 */
@Component
public interface ShopMapper{
    @Select("select price from si_game_island_shop where fid = #{id} and type = 1")
    Double getShopById(Integer id);

    @Select("select number from si_game_user_fruit where uid = #{uid} and fid = #{id}")
    String getFruitNum(int uid, Integer id);

    @Select("select price from si_game_island_shop where fid = #{id} and type = 2")
    Double getFruitPrice(Integer id);

    @Update("update si_game_user_fruit set number = number - #{number} where uid = #{uid} and fid = #{id}")
    void updateFruitNum(int uid, Integer id, String number);

    @Select("select count(*) from si_game_island_shop where type = 1")
    int selectFoodNum();

    @Select("select count(*) from si_game_island_shop where type = 2")
    int selectFruitNum();

    @Insert("insert into si_game_user_food(fid, uid) values (#{fid}, #{userId})")
    void insertNewUserFood(int fid, int userId);


    @Insert("insert into si_game_user_fruit(fid, uid) values (#{fid}, #{userId})")
    void insertNewUserFruit(int fid, int userId);

    @Update("update si_game_user_fruit set number = number + #{number} where uid = #{uid} and fid = #{fid}")
    void updateFruit(int uid, int fid, Integer number);


    @Select("select fid from si_game_island_shop where fid = #{id} and type = 1")
    Integer getFoodById(Integer id);

    @Select("select fid from si_game_island_shop where fid = #{id} and type = 2")
    Integer getFruitById(Integer id);

    @Select("select s2.fid,s1.number from si_game_user_fruit s1  left join si_game_island_shop s2 on s1.fid = s2.fid where s1.uid = #{id} and s2.type =2")
    List<Map<String, Object>> getFruitNameNum(int id);

    @Select("select name from si_game_island_shop where fid = #{id} and type = 2")
    String getFruitByName(Integer id);


    @Select("select name from si_game_island_shop where fid = #{id} and type = 1")
    String selectFoodName(Integer id);
}
